<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="Cache-control" content="no-cache">

	<%-- CSS Style Declarations --%>
	<link rel ="stylesheet" type="text/css" href="css/style.css" ></link>
	
		<%-- Java imports --%>
	<%@ page import="java.io.*" %>
	<%@ page import="java.util.*" %>
	<%@ page import="org.eclipse.wtp.sample.flashcards.FlashCardSet" %>
	

	<title>Quiz-O-Matic</title>
</head>

<body>

<div id="center-wrapper">
<div id="center-column">

<!-- Header -->
<div id="header">
</div> <!-- header -->


<!-- Page Title -->
<div style="
	position: absolute;
	top: 50px;
	width:600px;
	text-align:center;
	font-size:50px;
	">
	Quiz-O-Matic
</div> <!-- page title -->
	
<!-- Page Form -->	
<form action="/FlashCards/Setup" method="post">
	
<!-- Select Dictionary -->
<div style="
	position:absolute;
	top: 140px;
	left: 0px;
	width:600px;
	text-align:center;
	">
	Dictionary:
	<select name="set">
	<!-- comment -->
	<%
	if (request.getSession().getAttribute("dictionarylist") == null) {
		// load dictionary titles from file
		ArrayList<String> dictionarylist = new ArrayList<String>();
		System.out.println("Loading Dictionary Titles");
		response.setContentType("text/html");
		String filename = "/data/dictionaries.txt";
		ServletContext context = getServletContext();
		InputStream inp = context.getResourceAsStream(filename);
		if (inp != null) {
			InputStreamReader isr = new InputStreamReader(inp);
			BufferedReader reader = new BufferedReader(isr);
			String title = "";
			// read one entry
			while ((title = reader.readLine()) != null) {
				dictionarylist.add(title);
			}
		}	
		// register list with Session
		request.getSession().setAttribute("dictionarylist", dictionarylist);	
	}
	else {
		System.out.println("Didn't need to load from file");
	}
	// generate list of dictionaries from list registered with session
	ArrayList<String> locallist = (ArrayList<String>)request.getSession().getAttribute("dictionarylist");
	Iterator itr = locallist.iterator();
	while (itr.hasNext()) {
		String selected = "";
		String title = (String)itr.next();
		FlashCardSet localset = (FlashCardSet)request.getSession().getAttribute("flashcardset");

		if (localset != null ) {
			if (localset.getTitle().equals(title)) {selected = " selected=\"selected\"";}
		}
		out.println("<option value=\"" + title + "\"" + selected + ">" + title + "</option>");
	}
	%>
	Iterator itr =  
	</select>
</div> <!-- select dictionary -->

<!-- User Select -->
<div style="
	position:absolute;
	top: 200px;
	width:600px;
	text-align:center;
	">
	User <input type="text" class="text" size="15" maxlength="20" name="name" />
	Password <input type="text" class="text" size="15" maxlength="20" name="pass" />
	<input type="submit" value="Login" />
	<input type="submit" value="New User" />
</div> <!-- user select -->

<!-- Mode Select -->
<div style="
	position:absolute;
	top: 300px;
	width: 600px;
	text-align:center;
	">
	<input
		type="submit"
		class="bigbutton"
		name="mode"
		value="Start Quiz"
		title="">
	<input
		type="submit"
		class="bigbutton"
		name="mode"
		value="Lookup"
		title="">
	<input
		type="submit"
		class="bigbutton"
		name="mode"
		value="Edit Dictionary"
		title="">
	<input
		type="submit"
		class="bigbutton"
		name="mode"
		value="New Dictionary"
		title="">
</div> <!-- mode select -->
</form> <!-- page form -->

</div> <!-- center-column -->
</div> <!-- center-wrapper -->
</body>
</html>